www.gusucode.com > matlab神经网络原理与实例精解 本书源文件 > 第11章 用GUI设计神经网络/som_test.m

    % Solve a Clustering Problem with a Self-Organizing Map
% Script generated by NCTOOL
% Created Sun Mar 11 13:48:36 CST 2012
%
% This script assumes these variables are defined:
%
%   a - input data.
rng(0)
% 自定义语句------------------------
a= [0.9659    0.2588   -0.2588    0.9659   -0.9659   -0.9659;...
0.2588    0.9659    0.9659   -0.2588   -0.2588    0.2588];
% ---------------------------------
inputs = a;

% Create a Self-Organizing Map
dimension1 = 2;
dimension2 = 2;
net = selforgmap([dimension1 dimension2]);

% Train the Network
[net,tr] = train(net,inputs);

% Test the Network
outputs = net(inputs);

% View the Network
view(net)
% 自定义语句----------------------------
t=0:.2:2*pi+.2;
b=[cos(t);sin(t)];
y=sim(net,b);
y=vec2ind(y);
yu=unique(y);
N=length(yu);
fprintf('测试数据共分为 %d 类\n', N);
for i=1:N
    yu_num(i)=sum(y==yu(i));
    fprintf('第 %d 类包含 %d 个点\n', i, yu_num(i));
end
% ------------------------------------------

% Plots
% Uncomment these lines to enable various plots.
%figure, plotsomtop(net)
%figure, plotsomnc(net)
%figure, plotsomnd(net)
%figure, plotsomplanes(net)
%figure, plotsomhits(net,inputs)
%figure, plotsompos(net,inputs)

plot(b(1,y==yu(1)),b(2,y==yu(1)),'ro');
hold on;
plot(b(1,y==yu(2)),b(2,y==yu(2)),'b+');
plot(b(1,y==yu(3)),b(2,y==yu(3)),'k*');
plot(b(1,y==yu(4)),b(2,y==yu(4)),'m^');
hold off;
legend('第一类','第二类','第三类','第四类');